#!/bin/bash

cp -rf tools dist/

CJS_CREATE="
worker = new node_worker_threads_1.Worker(\`\${__dirname}/circle-miner-worker.js\`, { workerData: { threadCount, index, blockHeaderHexString, platform, arch }, });
"
echo $CJS_CREATE;

MJS_CREATE="
const filename = fileURLToPath(import.meta.url); const dirname = path.dirname(filename); worker = new Worker(\`\${dirname}/circle-miner-worker.js\`, { workerData: { threadCount, index, blockHeaderHexString, platform, arch }, });
"
echo $MJS_CREATE;


sed -ie 's|//WORKER_CREATION|worker = new node_worker_threads_1.Worker(\`\${__dirname}/circle-miner-worker.js\`, { workerData: { threadCount, index, blockHeaderHexString, platform, arch }, });|' ./dist/cjs/circle-miner.js
sed -ie 's|//WORKER_CREATION|const filename = fileURLToPath(import.meta.url); const dirname = path.dirname(filename); worker = new Worker(\`\${dirname}/circle-miner-worker.js\`, { workerData: { threadCount, index, blockHeaderHexString, platform, arch }, });|' ./dist/mjs/circle-miner.js

cat >dist/cjs/package.json <<!EOF
{
    "type": "commonjs"
}
!EOF

cat >dist/mjs/package.json <<!EOF
{
    "type": "module"
}
!EOF
